package Server;

import java.util.HashMap;
import java.util.Map;

public class RefList {
	private Map<String, Integer> refList;
	
	public RefList(){
		this.refList = new HashMap<String, Integer>();
	}
	
	public void addEntry(String filename){
		this.refList.put(filename, 1);
	}
	
	public void removeEntry(String filename){
		if (this.refList.get(filename) != null){
			this.refList.remove(filename);
		}
		return;
	}
	
	public boolean hasEntry(String filename){
		if (this.refList.get(filename) != null){
			return true;
		}
		return false;
	}
	
	// increment ref-count for 'filename' by 'count'
	public void addCount(String filename, int count){
		if (this.refList.get(filename) == null){
			return;
		}
		int c = this.refList.get(filename);
		this.refList.put(filename, c+count);
		return;
	}
	
	// increment ref-count for 'filename' by 1
	public void addCount(String filename){
		addCount(filename, 1);
	}
	
	public void remCount(String filename){
		if (this.refList.get(filename) == null){
			return;
		}
		int c = this.refList.get(filename);
			this.refList.put(filename, c-1);
		return;
	}
	
	//return the refCount of the filename or -1 if it doesn't exists
	public int getCount(String filename){
		if (this.refList.get(filename) == null){
			return -1;
		}
		return this.refList.get(filename);
	}
	
	public int getSize(){
		return refList.size();
	}
}
